package com.weiyun.shortlink.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.weiyun.shortlink.admin.common.convention.result.Result;
import com.weiyun.shortlink.admin.common.convention.result.Results;
import com.weiyun.shortlink.admin.remote.ShortLinkActualRemoteService;
import com.weiyun.shortlink.admin.remote.ShortLinkRemoteService;
import com.weiyun.shortlink.admin.remote.dto.req.RecycleBinRecoverReqDto;
import com.weiyun.shortlink.admin.remote.dto.req.RecycleBinRemoveReqDto;
import com.weiyun.shortlink.admin.remote.dto.req.RecycleBinSaveReqDto;
import com.weiyun.shortlink.admin.remote.dto.req.ShortLinkRecyclePageReqDto;
import com.weiyun.shortlink.admin.remote.dto.resp.ShortLinkPageRespDto;
import com.weiyun.shortlink.admin.service.RecycleBinService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/***
 *   @Author:weiyun
 *
 */
@RestController
@RequiredArgsConstructor
public class RecycleBinController {
    ShortLinkRemoteService shortLinkRemoteService = new ShortLinkRemoteService() {};
    private final RecycleBinService recycleBinService;
    private final ShortLinkActualRemoteService shortLinkActualRemoteService;
    @PostMapping("/api/shortLink/admin/v1/recycle-bin/save")
    public Result<Void> saveRecycleBin(@RequestBody RecycleBinSaveReqDto requestParam){
        shortLinkActualRemoteService.save(requestParam);
        return Results.success();
    }
    @GetMapping("/api/shortLink/admin/v1/recycle-bin/page")
    public  Result<Page<ShortLinkPageRespDto>> pageShortLink(ShortLinkRecyclePageReqDto requestParam){
        return shortLinkActualRemoteService.pageRecycleBin(requestParam.getGid(),requestParam.getCurrent(),requestParam.getSize());
    }

    @PostMapping("/api/shortLink/admin/v1/recycle-bin/recover")
    public Result<Void> recoverRecycleBin(@RequestBody RecycleBinRecoverReqDto requestParam){
        shortLinkActualRemoteService.recoverShortLink(requestParam);
        return Results.success();
    }

    @PostMapping("/api/shortLink/admin/v1/recycle-bin/delete")
    public Result<Void> removeRecycleBin(@RequestBody RecycleBinRemoveReqDto requestParam){
        shortLinkActualRemoteService.removeShortLink(requestParam);
        return Results.success();
    }

}
